package JDBC;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

/*
* 需求：将主人表的信息保留到集合中，遍历集合
* */
public class Test_Entity extends JDBCUtil{
    public static void main(String[] args) throws Exception {
        ArrayList<master> list = new ArrayList<>();
        String sql="select * from master";
         connection = JDBCUtil.getConnection();
         statement = connection.prepareStatement(sql);
         resultSet = statement.executeQuery();
        while (resultSet.next()){
           int id= resultSet.getInt("userid");
            String user = resultSet.getString("username");
            String userpassword = resultSet.getString("userpassword");
            master master = new master(id,user,userpassword);
            list.add(master);

        }
        for (master m:list){
            System.out.println(m);
        }
        //释放资源
        close(resultSet, statement, connection);

    }
}
